/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-10-11
 * Time: 13:36
 */
public class test1 {
    public static String bigAdd(String numStr1, String numStr2) {
        // write code here
        String[] str1Parts = numStr1.split("\\.");
        String[] str2Parts = numStr2.split("\\.");
        String str1Int = str1Parts[0];
        String str1Dec = str1Parts.length>1?str1Parts[1]:"";
        String str2Int = str2Parts[0];
        String str2Dec = str2Parts.length>1?str2Parts[1]:"";

        // 补齐小数部分长度
        int maxDecLen = Math.max(str1Dec.length(),str2Dec.length());
        if(maxDecLen>0){
            str1Dec = padRight(str1Dec,maxDecLen);
            str2Dec = padRight(str2Dec,maxDecLen);
        }


        // 小数相加
        long decSum = 0;
        if(!str1Dec.isEmpty()){
            decSum+=Long.parseLong(str1Dec);
        }
        if(!str2Dec.isEmpty()){
            decSum+=Long.parseLong(str2Dec);
        }
        String decSumStr = String.valueOf(decSum);
        decSumStr = padRight(decSumStr,maxDecLen);

        // 处理进位
        int carry = 0;
        if(decSumStr.length()>maxDecLen){
            carry=1;
            decSumStr = decSumStr.substring(1);
        }

        //整数相加
        String intSum = addStrings(str1Int,str2Int)+carry;
        if(decSumStr.isEmpty()){
            return intSum.substring(0,intSum.length()-1);
        }else{
            return (intSum+"."+decSumStr).substring(0,(intSum+"."+decSumStr).length()-1);
        }
    }

    private static String padRight(String s, int length) {
        if(s.length()>=length){
            return s;
        }
        StringBuilder builder = new StringBuilder();
        for(int i=0;i<length-s.length();i++){
            builder.append('0');
        }
        return builder.toString();
    }

    private static String addStrings(String num1,String num2){
        int i = num1.length()-1;
        int j = num2.length()-1;

        int carry = 0;
        StringBuilder builder = new StringBuilder();
        while(i>=0 || j>=0 || carry>0){
            int sum = carry;
            if(i>=0){
                sum += num1.charAt(i--)-'0';
            }
            if(j>=0){
                sum += num2.charAt(j--)-'0';
            }
            carry = sum/10;
            builder.append(sum%10);
        }
        return builder.reverse().toString();
    }

    public static void main(String[] args) {
        String a = "9007199254740991";
        String b = "1234567899999999999";

        System.out.println(bigAdd(a,b));
    }
}
